package com.yunupmall.controller.amdin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunupmall.api.fordVO.CommiditySpecesVo;
import com.yunupmall.api.fordentity.SpecsCommodity;
import com.yunupmall.service.admin.service.SpecsCommdityService;
import com.yunupmall.uits.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/specsCommdity")
public class SpecsCommdityController {
    private final SpecsCommdityService specCommdityService;
    private final Result result;


    /**
     * 新增商品规格
     * @param commiditySpecesVo
     * @return
     */
    @PostMapping("/BatchInsert")
    public Result<String> insertSpecsAllData(@RequestBody CommiditySpecesVo commiditySpecesVo) {
        try {
            return result.ok(specCommdityService.insertSpect(commiditySpecesVo));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }
    /**
     * 商品规格
     */
    @GetMapping("/page")
    public Result<Page<SpecsCommodity>> getList(@RequestParam(value = "id") Integer cId, @RequestParam(value = "page") Integer page, @RequestParam(value = "limit") Integer limit) {
        try {
            return result.ok(specCommdityService.getList(cId,page,limit));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }
    /**
     * 删除商品规格
     */
    @GetMapping("/del")
    public Result<String> del(@RequestParam Integer id) {
        try {
            return result.ok(specCommdityService.del(id));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }
}
